import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
 * Created by liuwei on 2017/11/24.
 */
public class MapTest {


    public  static void  main(String [] args) {
        Map map = new HashMap<String,ArrayList>();
        List list = new ArrayList();
        list.add(1);
        map.put("1",list);
        System.out.println(map);
        list.add("2");
        System.out.println(map);

//        String userIds = String.format("~", list);
        String userIds = StringUtils.join(list.toArray(),"~");
        System.out.println(userIds);

        Map map2 = new HashMap<String,Object>();
        map2.put("projectId", "123");
        String content = JSON.toJSONString(map2);
        System.out.println(content);

        String projectId = null;
        String newProjectId = projectId == null ? "" : projectId;
        System.out.println("+"+newProjectId+"-");


        Set list2 = new HashSet();
        list2.add(1);
        list2.add(1);

        String receiverIds = org.apache.commons.lang.StringUtils.join(list2.toArray(),"~");
        System.out.println(isMatch("ab","?*"));


    }


    public static boolean matchChar(char c, char p) {
        return (p == '?' || p == c);
    }

    public static boolean isMatch(String s, String p) {
        if (s == null || p == null) {
            return false;
        }

        int indexS = 0;
        int indexP = 0;

        int lenS = s.length();
        int lenP = p.length();

        int preS = 0;
        int preP = 0;

        boolean back = false;

        while (indexS < lenS) {
            if (indexP < lenP && matchChar(s.charAt(indexS), p.charAt(indexP))) {
                indexS++;
                indexP++;
            } else if (indexP < lenP && p.charAt(indexP) == '*') {
                while (indexP < lenP && p.charAt(indexP) == '*') {
                    indexP++;
                }

                //P的最后一个是 *，表示可以匹配任何字符串
                if (indexP == lenP) {
                    return true;
                }

                // 记录下这个匹配位置。
                back = true;
                preS = indexS;
                preP = indexP;
            } else if (back) {
                indexS = ++preS;
                indexP = preP;
            } else {
                return false;
            }
        }

        // 跳过末尾的所有的*.
        while (indexP < lenP && p.charAt(indexP) == '*') {
            indexP++;
        }

        if (indexS == lenS && indexP == lenP) {
            return true;
        }

        return false;
    }

}
